from PIL import Image, ImageDraw

# 加载图片
image_path = "map_20250125_203708448.png"  # 替换为你的图片路径
image = Image.open(image_path)

# 创建一个绘图对象
draw = ImageDraw.Draw(image)
width, height = image.size

# 定义矩形的坐标 (左上角 x, 左上角 y, 右下角 x, 右下角 y)
# 1848 x 1016
# left: 110
# top: 70
# right: 1848 - 1790 = 60
# bottom: 1016 - 940 = 80
# rectangle_coords = (110, 70, 1790, 940)  # 替换为你想要的矩形坐标
left = 100
top = 100
right = 100
bottom = 100
rectangle_coords = (left, top, width - right, height - bottom)  # 替换为你想要的矩形坐标

# 定义矩形的边框颜色和宽度
rectangle_color = "red"  # 矩形边框颜色
rectangle_width = 5      # 矩形边框宽度

# 在图片上绘制矩形
draw.rectangle(rectangle_coords, outline=rectangle_color,
               width=rectangle_width)

# 保存绘制后的图片
output_path = "maprect.png"  # 替换为你想保存的路径
image.save(output_path)

print(f"图片已保存到: {output_path}")
